﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimerJobServer.Common.Mina;
using log4net.Appender;

namespace TimerJobServer
{
    public class MinaLogAppender:AppenderSkeleton
    {
        public MinaServerHandler minaServerHandler { get; set; }

        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            var message = RenderLoggingEvent(loggingEvent);
            if (!string.IsNullOrEmpty(message)&& minaServerHandler!=null)
            {
                foreach (var item in minaServerHandler.sessions)
                {
                    TransferObj obj = new TransferObj()
                    {
                        Type = TranType.Log,
                        Log = message
                    };
                    item.Value.Write(obj);
                }
            }
        }
    }
}
